package com.jxsd.edu.cn.struts2.serviceImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.SearchPubMsgDao;
import com.jxsd.edu.cn.struts2.daoImpl.SearchPubMsgDaoImpl;
import com.jxsd.edu.cn.struts2.models.PubMsgview;
import com.jxsd.edu.cn.struts2.services.SearchPubMsgService;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;
import com.jxsd.edu.cn.tools.Participle;
import com.jxsd.edu.cn.tools.StringTool;

public class SearchPubMsgServiceImpl  implements  SearchPubMsgService
{
    private   SearchPubMsgDao  dao=new  SearchPubMsgDaoImpl();
	@Override
	public Page<PubMsgview> doDearch(PageBean<PubMsgview>  pagebean,String keyword) 
	{
		Page<PubMsgview>  page=dao.doDearch(pagebean, keyword);
		if(keyword.length()>1)
		{
			//高亮标示分词关键字
			List<String>  list=Participle.getStrings(keyword);
			
			if(null!=list&&list.size()>=1)
			{
				for(PubMsgview  view:page.getList())
				{
					for(String s:list)
					{
						String title=view.getTitle();
						title=StringTool.replaceString(title, s, "<font color='#FF0000' >"+s+"</font>");
						view.setTitle(title);
					}
				}
			}
			
		}else
		{
			for(PubMsgview  view:page.getList())
			{
				String title=view.getTitle();
				title=StringTool.replaceString(title, keyword, "<font color='#FF0000' >"+keyword+"</font>");
				view.setTitle(title);
			}
		}
		
		return page;
	}
   
}
